Function.prototype.inherits = function(parent) {
	var d = {}, p = (this.prototype = new parent());
    p.constructor = this;
    p.superclass = parent;
    this.prototype.uber = function(name) {
    	if (!(name in d)) {
    		d[name] = 0;
        }
    	var f, r, t = d[name], v = parent.prototype;
    	if (t) {
        	while (t) {
        		v = v.superclass.prototype;
        		if (v.hasOwnProperty(name)) {
        			t -= 1;
        		}
        	}
        	f = v[name];
        } else {
        	f = p[name];
        	if (f == this[name]) {
        		f = v[name];
        	}
        }
        d[name] += 1;
        if (f == this[name]) {
        	r = this.uber.apply(this, Array.prototype.slice.apply(arguments));
        } else {
        	r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
        }
        d[name] -= 1;
        return r;
    };
    return this;
};

function LeopardModel() { this._ps_ = {}; this._mt_ = {}; };
LeopardModel.prototype.verify = function() {
	var checking = function(onerule, implant) {
		if (onerule.mixrule) {
			var msg = onerule.comment || _p_;
			var min = onerule.mixrule.min;
			if (min) {
				if (parseFloat(implant) < parseFloat(min)) {
					throw msg + '\u4e0d\u80fd\u5c0f\u4e8e' + min;
				}
			}
			var max = onerule.mixrule.max;
			if (max) {
				if (parseFloat(implant) > parseFloat(max)) {
					throw msg + '\u4e0d\u80fd\u5927\u4e8e' + max;
				}
			}
			var reg = onerule.mixrule.reg;
			if (reg) {
				reg = new RegExp(reg, ('g'));
				if (!implant.toString().match(reg)) {
					throw msg + '\u683c\u5f0f\u4e0d\u6b63\u786e';
				}
			}
		}
	};
	var recursed = function(model) {
		if (model._ps_) {
			for (var _p_ in model._ps_) {
				var chk = false;
				if (model._ps_[_p_].require) {
					if (model[_p_]) {
						chk = true;
					} else {
						var msg = model._ps_[_p_].comment || _p_;
						throw (msg + '\u4e0d\u80fd\u4e3a\u7a7a');
					}
				} else {
					if (model[_p_]) {
						chk = true;
					}
				}
				if (chk) {
					var implants = model[_p_];
					if ((typeof implants != 'array')
							&& !(implants instanceof Array)) {
						implants = [implants];
					}
					for (var i = 0; i < implants.length; i ++) {
						var implant = implants[i];
						if (model._ps_[_p_].referer) {
							var _referer = new model._ps_[_p_].referer();
							implant = _referer.object(implant);
						}
						if (implant instanceof LeopardModel) {
							recursed(implant);
						} else {
							checking(model._ps_[_p_], implant);
						}
					}
				}
			}
		}
	};
	recursed(this);
};
LeopardModel.prototype.object = function(object) {
	if (object) {
		for (var p in object) { this[p] = object[p]; }
		return this;
	} else {
		return JSON.parse(JSON.stringify(this));
	}
};
LeopardModel.prototype.string = function() {
	return JSON.stringify((this.object()));
};
LeopardModel.prototype.remote = 
			function(callback, errparse) {
	try {
		this.verify();
	} catch (e) {
		if (typeof errparse == 'function') {
			errparse({ val : 1, msg : e });	 return;
		} else { throw e; }
	}
	if (!this._mt_.url) { throw '_mt_.url : null'; }
	this._mt_.data = 
			$.extend(this._mt_.data, this.object());
	var options = {
			type : 'post',
			dataType : 'json',
			timeout : 1e4,
			error : function(xhr, e) {
				if (typeof errparse == 'function') {
					e = { val : 0, msg : e };
					errparse(e); return;
				} else { throw e; }
			},
			success : function( response ) {
				if (typeof callback == 'function') {
					callback( response );
				}
			}
	};
	$.ajax($.extend(options, this._mt_));
};